<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>index</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/element-ui/2.13.2/theme-chalk/index.css" rel="stylesheet">
</head>
<body>
<div id="app">
    <h2>单点登录测试(spring boot+spring security)</h2>
    <el-button type="primary" @click="login">登录</el-button>
    <el-button type="primary" @click="locationMe()">访问受保护的接口</el-button>
    <el-button type="danger" @click="logout">退出</el-button>
    <h2>当前登录信息： </h2>
    <div style="color: blue;font-size: large;">
        登录状态：{{currUser.userId?"已登录":"未登录"}}
        <div v-if="currUser.userId">
            <br>
            id：{{currUser.userId}}
            <br>
            access_token：{{currUser.accessToken}}
            <br>
            client：{{currUser.client}}
        </div>
    </div>
</div>
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/element-ui/2.13.2/index.js"></script>
<script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
<script>
    port = 8081;
    if (window.location.href.indexOf("8081") === -1) {
        port = 8082;
    }
    new Vue({
        el: '#app',
        data: {
            currUser: "",
        },
        methods: {
            me() {
                let _this = this;
                $.get("/users/me", function (data) {
                    _this.currUser = data;
                })
            },
            locationMe() {
                window.location.href = "/users/me";
            },
            logout() {
                window.location.href = "/logout"
            },
            login() {
                window.location.href = "http://localhost:" + port + "/sso/login";
            },
        }
        ,
        created: function () {
            this.me();
        }
    })
</script>
</body>
</html>